package config

import (
	shared "github.com/devops-smartbot/devops-smartbot/shared/config"
)

// Config wraps shared configuration with gateway specific settings.
type Config struct {
	HTTPPort int

	AlertServiceAddr       string
	TicketServiceAddr      string
	AIServiceAddr          string
	IntegrationServiceAddr string
	JWTSecret              string
}

// FromShared constructs gateway config derived from shared config values.
func FromShared(cfg *shared.Config) Config {
	// Use services config if available, otherwise fallback to defaults
	alertAddr := cfg.Services.AlertService
	if alertAddr == "" {
		alertAddr = "alert-service:50051"
	}

	ticketAddr := cfg.Services.TicketService
	if ticketAddr == "" {
		ticketAddr = "ticket-service:50052"
	}

	aiAddr := cfg.Services.AIService
	if aiAddr == "" {
		aiAddr = "ai-gateway:50053"
	}

	integrationAddr := "integration-service:50056" // Default integration service address

	jwtSecret := cfg.App.JWTSecret
	if jwtSecret == "" {
		jwtSecret = "devops-smartbot-secret-key-change-in-production"
	}

	return Config{
		HTTPPort: cfg.App.HTTPPort,

		AlertServiceAddr:       alertAddr,
		TicketServiceAddr:      ticketAddr,
		AIServiceAddr:          aiAddr,
		IntegrationServiceAddr: integrationAddr,
		JWTSecret:              jwtSecret,
	}
}
